//
//  SearchBar.m
//  ProjectforHDX
//
//  Created by Jaesun on 16/8/3.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "SearchBar.h"

@implementation SearchBar


- (instancetype)init {
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
        [self s_setupViews];
    }
    return  self;
}

- (void)s_setupViews {
    
    self.backgroundColor = [UtilCheck hexStringToColor:@"e7e7e7" alpha:1];
    // backBtn
    {
        self.backBtn = [[RZCustomButtom alloc] initWithFrame:CGRectMake(0, 25, 48, 30)];
        [self.backBtn setImage:BDFILEIMAGENAEM(@"default/back_gray") forState:(UIControlStateNormal)];
        [self.backBtn addTarget:self action:@selector(touchBackBtn:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:self.backBtn];
    }
    
    // inputBGView
    {
        self.inputBGView = [[UIView alloc] initWithFrame:CGRectMake(self.backBtn.right, self.backBtn.top, self.width - self.backBtn.width - 20, self.backBtn.height)];
        self.inputBGView.layer.cornerRadius = 5;
        self.inputBGView.layer.masksToBounds = YES;
        self.inputBGView.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.inputBGView];
    }
    
    // searchIconView
    {
        UIImage *image = BDFILEIMAGENAEM(@"default/img_search");
        self.searchIconView = [[RZCustomImageView alloc] initWithFrame:CGRectMake(5, CGRectGetMidY(self.inputBGView.bounds) - image.size.height / 2.0, image.size.width, image.size.height)];
        self.searchIconView.image = image;
        [self.inputBGView addSubview:self.searchIconView];
    }
    
    // keyWordText
    {
        self.keyWordText = [[UITextField alloc] initWithFrame:CGRectMake(self.searchIconView.right + 5, 0,self.inputBGView.width - self.searchIconView.width - 5 * 3, self.inputBGView.height)];
        self.keyWordText.returnKeyType = UIReturnKeySearch;
        self.keyWordText.font = CustomFont(14.5);
        self.keyWordText.textColor = [UtilCheck hexStringToColor:@"c9c9cf" alpha:1];
        self.keyWordText.clearButtonMode = UITextFieldViewModeUnlessEditing;
        
        self.keyWordText.placeholder = [UtilCheck language:@"setting.inputPlate"]; // 请输入板件名称/板件号
        [self.keyWordText setValue:[UIFont boldSystemFontOfSize:14.5] forKeyPath:@"_placeholderLabel.font"];
        self.keyWordText.delegate = self;
        self.keyWordText.keyboardType = UIKeyboardTypeASCIICapable;
        [self.inputBGView addSubview:self.keyWordText];
    }
}

- (void)touchBackBtn:(RZCustomButtom *)sender {
    self.back();
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    self.textBlcok(textField.text);
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

@end
